package com.ouyang.dao.RentPeople;

import com.ouyang.dao.DataBaseDao;
import com.ouyang.poji.Oders;
import com.ouyang.poji.RentPeople;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class RentPeopleDaoImpl implements RentPeopleDao {
    @Override
    public List<RentPeople> getrentpeoplelist () {
        Connection connection = DataBaseDao.getConnection();
        PreparedStatement statement = null;
        String sql = "select User.Id,UserName,cdbName,OrderNumber,Email from User,oders where User.UserName = oders.RentPeople";
        ResultSet rs = null;
        List<RentPeople> list = new ArrayList<>();
        try {
            statement = connection.prepareStatement(sql);
            rs = statement.executeQuery();
            while (rs.next()){
                RentPeople rentPeople = new RentPeople();
                rentPeople.setId(rs.getInt(1));
                rentPeople.setRentpeople(rs.getString(2));
                rentPeople.setEmail(rs.getString(5));
                rentPeople.setCdbname(rs.getString(3));
                rentPeople.setOrdernumber(rs.getString(4));
                list.add(rentPeople);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            DataBaseDao.closeResource(connection,statement,rs);
        }
        return list;
    }
}
